<template>
	<view class="content">
		<view class="con">
			<view class="unit" v-show="current === 0">
				<view class="title">单位信息</view>
				<view>
					单位名称
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="companyName" placeholder="请输入单位名称" />
				<view>
					单位地址
					<text class="huang">※</text>
				</view>
				<view class="" style="display: flex;">
					<!-- <view class="uni-input" style="color: #333333;">河北省</view> -->
					<picker mode="selector" id="SHI" :value="SHIindex" range-key="label" :range="SHI" @change="bindPickerChange">
						<view class="uni-input">{{ SHI[SHIindex]['label'] }}</view>
					</picker>
					<picker v-if="xianShow" mode="selector" id="XIAN" :value="XIANindex" range-key="label" :range="XIAN" @change="bindPickerChange">
						<view class="uni-input">{{ XIAN[XIANindex]['label'] }}</view>
					</picker>
				</view>
				<!-- <picker id="city" @change="bindPickerChange" :value="cityIndex" mode="region">
					<view class="uni-input">{{ city[0] }}，{{ city[1] }}，{{ city[2] }}</view>
				</picker> -->
				<picker id="JD" @change="bindPickerChange" :value="JDindex" range-key="label" :range="JD" v-if="jdShow">
					<view class="uni-input">{{ JD[JDindex]['label'] }}</view>
				</picker>
				<picker id="PCS" @change="bindPickerChange" :value="PCSindex" range-key="label" :range="PCS" v-if="pcsShow">
					<view class="uni-input">{{ PCS[PCSindex]['label'] }}</view>
				</picker>
				<input type="text" v-model="address" style="height: 100upx;" placeholder="请输入详细地址" />
				<view class="title">法人信息</view>
				<view>
					法人姓名
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="LegalPersonName" placeholder="请输入法人姓名" />
				<view>
					法人性别
					<text class="huang">※</text>
				</view>
				<radio-group @change="radioChangeLegalSex">
					<label class="radio">
						<radio value="0" checked="true" color="#fcd700" />
						男
					</label>
					<label class="radio">
						<radio value="1" color="#fcd700" />
						女
					</label>
				</radio-group>
				<view>
					法人身份证号
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="identityNumber" placeholder="请输入法人身份证号" />
				<view>
					法人手机号
					<text class="huang">※</text>
				</view>
				<input type="number" v-model="phoneNumber" placeholder="请输入法人手机号" />
				<view class="title">申请人信息</view>
				<view>
					申请人姓名
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="ApplicantName" placeholder="请输入申请人姓名" />
				<view>
					申请人手机号
					<text class="huang">※</text>
				</view>
				<input type="number" v-model="ApplicantNumber" placeholder="请输入申请人手机号" />

				<view>
					验证码
					<text class="huang">※</text>
				</view>
				<input type="number" style="width: 200upx;" v-model="ma" placeholder="请输入验证码" />
				<button @tap="faMa" v-show="isFa" type="primary" style="font-size: 26upx;width: 200upx;height: 64upx;line-height:64upx;margin-top: -70upx;">发送验证码</button>
				<button v-show="!isFa" style="font-size: 26upx;width: 200upx;height: 64upx;line-height:64upx;margin-top: -70upx;"
				 disabled>{{ miao }}秒</button>

				<view class="title">犬只信息</view>
				<view>
					犬只名称{{ dogName }}
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="dogName" placeholder="请输入犬只名称" disabled="" />
				<view>
					犬只雌雄
					<text class="huang">※</text>
				</view>
				<label class="radio" v-if="dogSex === '1'">
					<radio value="0" checked="true" color="#fcd700" />
					公
				</label>
				<label class="radio" v-if="dogSex === '0'">
					<radio value="1" checked="true" color="#fcd700" />
					母
				</label>
				<!-- <radio-group>
					<label class="radio">
						<radio value="1" checked="true" color="#fcd700" />
						公
					</label>
					<label class="radio">
						<radio value="0" color="#fcd700" />
						母
					</label>
				</radio-group> -->
				<view>
					出生日期
					<text class="huang">※</text>
				</view>
				<!-- <input type="text" v-model="dogAgeValue.label" placeholder="请选择狗狗年龄" disabled @click="showMulLinkageTwoPicker" /> -->
				<input type="text" v-model="dogAgeValue" placeholder="请选择狗狗年龄" disabled />
				<view>
					犬只品种
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="variety" disabled />
				<view>
					犬只最后注射疫苗时间
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="lastDate" disabled />
				<view class="title">图片上传</view>
				<view class="picBox" style="display: flex;flex-wrap: wrap;">
					<view>
						<text>
							犬只免疫证照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.mianyi" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.mianyi"></image>
											<!-- <view class="close-view" @click="close('mianyi')">x</view> -->
										</view>
									</block>
									<!-- <view class="uni-uploader__input-box" v-show="!imageList.mianyi"><view class="uni-uploader__input" @tap="chooseImg('mianyi')"></view></view> -->
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							营业执照
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.hukouben" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.hukouben"></image>
											<view class="close-view" @click="close('hukouben')">x</view>
										</view>
									</block>
									<view class="uni-uploader__input-box" v-show="!imageList.hukouben">
										<view class="uni-uploader__input" @tap="chooseImg('hukouben')"></view>
									</view>
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							房本或租房合同照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.fangben" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.fangben"></image>
											<view class="close-view" @click="close('fangben')">x</view>
										</view>
									</block>
									<view class="uni-uploader__input-box" v-show="!imageList.fangben">
										<view class="uni-uploader__input" @tap="chooseImg('fangben')"></view>
									</view>
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							犬只彩色照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.caizhao" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.caizhao"></image>
											<!-- <view class="close-view" @click="close('caizhao')">x</view> -->
										</view>
									</block>
									<!-- <view class="uni-uploader__input-box" v-show="!imageList.caizhao"><view class="uni-uploader__input" @tap="chooseImg('caizhao')"></view></view> -->
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="personal" v-show="current === 1">
				<view class="title">养犬人信息</view>
				<view>
					养犬人姓名
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="LegalPersonName" placeholder="请输入养犬人姓名" />
				<view>
					性别
					<text class="huang">※</text>
				</view>
				<radio-group @change="radioChangeLegalSex">
					<label class="radio">
						<radio value="0" checked="true" color="#fcd700" />
						男
					</label>
					<label class="radio">
						<radio value="1" color="#fcd700" />
						女
					</label>
				</radio-group>
				<view>
					身份证号
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="identityNumber" placeholder="身份证号" />
				<view>
					手机号
					<text class="huang">※</text>
				</view>
				<input type="number" v-model="phoneNumber" placeholder="手机号" />

				<view>
					验证码
					<text class="huang">※</text>
				</view>
				<input type="number" style="width: 200upx;" v-model="ma" placeholder="请输入验证码" />
				<button @tap="faMa" v-show="isFa" type="primary" style="font-size: 26upx;width: 200upx;height: 64upx;line-height:64upx;margin-top: -70upx;">发送验证码</button>
				<button v-show="!isFa" style="font-size: 26upx;width: 200upx;height: 64upx;line-height:64upx;margin-top: -70upx;"
				 disabled>{{ miao }}秒</button>

				<view>
					居（暂）住地
					<text class="huang">※</text>
				</view>
				<view class="" style="display: flex;">
					<!-- <view class="uni-input" style="color: #333333;">河北省</view> -->
					<picker mode="selector" id="SHI" :value="SHIindex" range-key="label" :range="SHI" @change="bindPickerChange">
						<view class="uni-input">{{ SHI[SHIindex]['label'] }}</view>
					</picker>
					<picker v-if="xianShow" mode="selector" id="XIAN" :value="XIANindex" range-key="label" :range="XIAN" @change="bindPickerChange">
						<view class="uni-input">{{ XIAN[XIANindex]['label'] }}</view>
					</picker>
				</view>
				<!-- <picker id="city" @change="bindPickerChange" :value="cityIndex" mode="region">
					<view class="uni-input">{{ city[0] }}，{{ city[1] }}，{{ city[2] }}</view>
				</picker> -->
				<picker id="JD" @change="bindPickerChange" :value="JDindex" range-key="label" :range="JD" v-if="jdShow">
					<view class="uni-input">{{ JD[JDindex]['label'] }}</view>
				</picker>
				<picker id="PCS" @change="bindPickerChange" :value="PCSindex" range-key="label" :range="PCS" v-if="pcsShow">
					<view class="uni-input">{{ PCS[PCSindex]['label'] }}</view>
				</picker>
				<input type="text" v-model="address" style="height: 100upx;" placeholder="请输入详细地址" />
				<view class="title">紧急联系信息</view>
				<view>
					紧急联系人姓名
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="contactName" placeholder="紧急联系人姓名" />
				<view>
					紧急联系人手机号
					<text class="huang">※</text>
				</view>
				<input type="number" v-model="ApplicantNumber" placeholder="请输入紧急联系人手机号" />
				<view class="title">犬只信息</view>
				<view>
					犬只名称
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="dogName" disabled />
				<view>
					犬只雌雄
					<text class="huang">※</text>
				</view>
				<label class="radio" v-if="dogSex === '1'">
					<radio value="0" checked="true" color="#fcd700" />
					公
				</label>
				<label class="radio" v-if="dogSex === '0'">
					<radio value="1" checked="true" color="#fcd700" />
					母
				</label>
				<!-- <radio-group @change="radioChangeDogSex">
					<label class="radio">
						<radio value="1" checked="true" color="#fcd700" />
						公
					</label>
					<label class="radio">
						<radio value="0" color="#fcd700" />
						母
					</label>
				</radio-group> -->
				<view>
					出生日期
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="dogAgeValue" disabled />
				<view>
					犬只品种
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="variety" disabled />
				<view>
					犬只最后注射疫苗时间
					<text class="huang">※</text>
				</view>
				<input type="text" v-model="lastDate" disabled />
				<view class="title">图片上传</view>
				<view class="picBox" style="display: flex;flex-wrap: wrap;">
					<view>
						<text>
							犬只免疫证照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.mianyi" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.mianyi"></image>
											<!-- <view class="close-view" @click="close('mianyi')">x</view> -->
										</view>
									</block>
									<!-- <view class="uni-uploader__input-box" v-show="!imageList.mianyi"><view class="uni-uploader__input" @tap="chooseImg('mianyi')"></view></view> -->
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							户口本或暂住证照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.hukouben" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.hukouben"></image>
											<view class="close-view" @click="close('hukouben')">x</view>
										</view>
									</block>
									<view class="uni-uploader__input-box" v-show="!imageList.hukouben">
										<view class="uni-uploader__input" @tap="chooseImg('hukouben')"></view>
									</view>
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							房本或租房合同照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.fangben" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.fangben"></image>
											<view class="close-view" @click="close('fangben')">x</view>
										</view>
									</block>
									<view class="uni-uploader__input-box" v-show="!imageList.fangben">
										<view class="uni-uploader__input" @tap="chooseImg('fangben')"></view>
									</view>
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							犬只彩色照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.caizhao" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.caizhao"></image>
											<!-- <view class="close-view" @click="close('caizhao')">x</view> -->
										</view>
									</block>
									<!-- <view class="uni-uploader__input-box" v-show="!imageList.caizhao"><view class="uni-uploader__input" @tap="chooseImg('caizhao')"></view></view> -->
								</view>
							</view>
						</view>
					</view>

					<view>
						<text>
							养犬人照片
							<text class="huang">※</text>
						</text>
						<view class="uni-uploader">
							<view class="uni-uploader-body">
								<view class="uni-uploader__files">
									<block>
										<view v-show="imageList.yqr" class="uni-uploader__file" style="position: relative;">
											<image class="uni-uploader__img" :src="imageList.yqr"></image>
											<view class="close-view" @click="close('yqr')">x</view>
										</view>
									</block>
									<view class="uni-uploader__input-box" v-show="!imageList.yqr">
										<view class="uni-uploader__input" @tap="chooseImg('yqr')"></view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view>
				办理犬牌、注射芯片地点
				<text class="huang">※</text>
			</view>
			<input type="text" v-model="injectionLocation" placeholder="请选择地点" disabled />
		</view>


		<view style="margin-bottom: 20upx;">
			<switch @change="switch1Change" />
			阅读并接受 <text @tap="showCns" style="color: #007AFF;padding-left: 20upx;">《承诺书》</text>
		</view>
		<view class="mark" v-show="isCns">
			<view class="guanbi_btn" @tap="showCns()">
				关闭
			</view>
			<image src="../../static/img/chengnuoshu.jpg" mode="aspectFit"></image>
		</view>
		<view class="" style="text-align: center;color: #888888;">
			<text>支付犬牌犬证费用，金额为 {{ money }} 元</text>
		</view>

		<view class="btn"><button type="default" style="background-color:#fcd700;" @click="submit">确认提交</button></view>
		<view class="wenzi">
			<view class="">禁止危险犬标准及品种</view>
			<view class="">{{ nowTime }}</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import uniSegmentedControl from '@/components/uni-segmented-control/uni-segmented-control.vue';
	import CHONG from '../../static/js/function.js';
	export default {
		computed: mapState(['URL', 'TOKEN']),
		data() {
			return {
				isShow: false,
				xianShow: false,
				pcsShow: false,
				jdShow: false,

				items: [{
						title: '单位养犬办牌',
						src: '../../static/img/danwei.png'
					},
					{
						title: '个人养犬办牌',
						src: '../../static/img/geren2.png'
					}
				], //头部选项卡
				current: 0, //选项卡 选中
				id: Number,
				companyName: '', //单位名称
				citypickerValue: [], //单位地址
				paichusuoJson: [],
				paichusuoValue: [],
				jiedaoJson: [],
				jiedaoValue: [],
				address: '', //详细地址
				LegalPersonName: '', //法人姓名
				legalSex: '0', //法人性别
				identityNumber: '', //法人身份证号
				ApplicantName: '', //申请人姓名
				ApplicantNumber: '', //申请人身份证号
				phoneNumber: '', //手机号
				dogName: '', //狗狗名字
				dogSex: '0', //狗狗性别
				dogAgeValue: [], //狗狗年龄
				variety: '', //狗狗品种
				lastDate: '', //最后疫苗注射时间
				imageList: {
					//狗狗 图片
					mianyi: '', //免疫证
					hukouben: '', //户口本
					fangben: '', //房本
					caizhao: '',
					yqr: '' //彩照
				},
				imgsData: {
					mianyi: '', //免疫证
					hukouben: '', //户口本
					fangben: '', //房本
					caizhao: '',
					yqr: '' //彩照
				},
				imgIndex: 0,
				contactName: '', //紧急联系人姓名
				injectionLocation: '', //注射芯片地点

				nowTime: new Date(), //登记日期

				// cityIndex: [2, 0, 0],
				PCSindex: 0,
				JDindex: 0,
				SHIindex: 0,
				XIANindex: 1,

				// city: ['河北省', '石家庄市', '长安区'],
				SHI: [],
				XIAN: [],
				PCS: [],
				JD: [],

				// cityCode: '130102',
				SHICode: '',
				XIANCode: '',
				JDCode: '',
				PCSCode: '',

				isFa: true,
				miao: 59,
				ma: '',
				bizId: '',
				
				money: ' ',
				isTongyi: false,
				isCns: false,
			};
		},
		onLoad() {
			this.imgIndex = 0;

			uni.getStorage({
				key: 'xinXi',
				success: res => {
					console.log(res.data);
					let json = res.data;
					if (json.atype === '1') {
						this.current = 0;
						this.id = json.id;
						this.dogName = json.dogName;
						this.dogSex = json.dogSex;
						this.dogAgeValue = json.dogAge;
						this.variety = json.retriever;
						this.lastDate = json.immuneTime;
						this.imgsData.mianyi = json.immunePic;
						this.imageList.mianyi = json.immunePic;
						this.imgsData.caizhao = json.dogAvatar;
						this.imageList.caizhao = json.dogAvatar;
						this.injectionLocation = json.injectionLocation;
					} else if (json.atype === '0') {
						this.current = 1;
						this.id = json.id;
						this.dogName = json.dogName;
						this.dogSex = json.dogSex;
						this.dogAgeValue = json.dogAge;
						this.variety = json.retriever;
						this.lastDate = json.immuneTime;
						this.imgsData.mianyi = json.immunePic;
						this.imageList.mianyi = json.immunePic;
						this.imgsData.caizhao = json.dogAvatar;
						this.imageList.caizhao = json.dogAvatar;
						this.injectionLocation = json.injectionLocation;
						console.log(this.dogName);
					}
				}
			});
		},
		mounted() {
			this.getShi();
			this.getMoney();
			// this.getJeidao(this.cityCode);
			// this.getPaichusuo(this.cityCode);
		},
		methods: {
			faMa() {
				this.isFa = false;
				let timer = setInterval(() => {
					this.miao--;
					if (this.miao === 0) {
						clearInterval(timer);
						this.isFa = true;
						this.miao = 59;
					}
				}, 1000);
				let phone = '';
				if (this.current === 0) {
					phone = this.ApplicantNumber;
				} else {
					phone = this.phoneNumber;
				}
				uni.request({
					url: this.URL + 'Sendchecked',
					data: {
						telephone: phone,
					},
					success: res => {
						console.log('返回的验证码');
						console.log(res.data);
						if (res.data.success) {
							this.bizId = res.data.data[0].bizId;
						} else {
							CHONG.tip('网路错误，请稍后再试');
						}
					}
				});
			},
			getMoney() {
				uni.request({
					url: this.URL + 'cost',
					success: res => {
						this.money = res.data.data[0].money;
					}
				});
			},
			showCns() {
				this.isCns = !this.isCns;
			},
			bindPickerChange(e) {
				console.log(e);
				// 			if (e.currentTarget.id === 'city') {
				// 				this.city = e.target.value;
				// 				this.cityCode = e.target.code[2];
				// 
				// 				this.getPaichusuo(e.target.code[2]);
				// 				this.getJeidao(e.target.code[2]);
				// 			} else
				if (e.currentTarget.id === 'SHI') {
					this.SHIindex = e.target.value;
					this.SHICode = this.SHI[this.SHIindex]['value'];
					this.XIAN = [];
					this.XIANCode = "";
					this.XIANindex = 1;

					this.JD = [];
					this.JDCode = "";
					this.JDindex = 0;

					this.PCS = [];
					this.PCSCode = "";
					this.PCSindex = 0;
					this.getXian(this.SHICode);
				} else if (e.currentTarget.id === 'XIAN') {
					this.JD = [];
					this.JDCode = "";
					this.JDindex = 0;

					this.PCS = [];
					this.PCSCode = "";
					this.PCSindex = 0;

					this.XIANindex = e.target.value;
					this.XIANCode = this.XIAN[this.XIANindex]['value'];
					this.getPaichusuo(this.XIANCode);
					this.getJeidao(this.XIANCode);
				} else if (e.currentTarget.id === 'PCS') {
					this.PCSindex = e.target.value;
					this.PCSCode = this.PCS[this.PCSindex]['value'];
				} else if (e.currentTarget.id === 'JD') {
					this.JDindex = e.target.value;
					this.JDCode = this.JD[this.JDindex]['value'];
				}
			},
			getShi() {
				uni.request({
					url: this.URL + 'shi',
					success: res => {
						// console.log("shi");
						// console.log(res.data);
						if (res.data.success) {
							this.SHI = res.data.data;
							this.getXian(this.SHI[0]['value']);
							this.SHICode = this.SHI[0]['value'];
							this.xianShow = true;
							// console.log(this.SHICode);
						}
					}
				});
			},
			getXian(code) {
				uni.request({
					url: this.URL + 'xian',
					data: {
						code: code
					},
					success: res => {
						console.log("xian");
						console.log(res.data);
						if (res.data.success) {
							this.XIAN = res.data.data;
							this.XIANCode = this.XIAN[1]['value'];
							this.getPaichusuo(this.XIANCode);
							this.getJeidao(this.XIANCode);
							this.getZhushedian(this.XIANCode);
						}
					}
				});
			},
			getZhushedian(code) {
				uni.request({
					url: this.URL + 'bzd',
					data: {
						code: code
					},
					success: res => {
						if (res.data.data.length > 0) {
							this.ZSD = res.data.data;
							this.zsdShow = true;
							this.ZSDCode = this.ZSD[this.ZSDindex]['value'];
							// } else {
							// 	CHONG.tip('该地区没有注射点，请重新选择');
							// 	this.zsdShow = false;
							// 	this.ZSDCode = '';
						}
						console.log(res.data);
					}
				});
			},
			getPaichusuo(code) {
				uni.request({
					url: this.URL + 'police',
					data: {
						code: code
					},
					success: res => {
						if (res.data.success) {
							this.PCS = res.data.data;
							this.pcsShow = true;
							this.PCSCode = this.PCS[this.PCSindex]['value'];
						} else {
							CHONG.tip("该地区没有派出所，请重新选择");
							this.pcsShow = false;
							this.PCSCode = '';
						}
					}
				});
			},
			getJeidao(code) {
				uni.request({
					url: this.URL + 'jie',
					data: {
						code: code
					},
					success: res => {
						if (!res.data.success) {
							// CHONG.tip("该地区没有街道，请重新选择");
							this.jdShow = false;
							this.JDCode = '';
						} else {
							this.JD = res.data.data;
							this.jdShow = true;
							this.JDCode = this.JD[this.JDindex]['value'];
						}
					}
				});
			},
			postGenren() {
				console.log('post');
				let data;
				if (this.current === 1) {
					console.log('geren');
					data = {
						wxid: this.TOKEN,
						id: this.id,
						atype: '0',
						name: this.LegalPersonName,
						sex: this.legalSex,
						useridno: this.identityNumber,
						phone: this.phoneNumber,
						code: this.JDCode || this.XIANCode,
						pcode: this.PCSCode,
						address: this.address,
						contactName: this.contactName,
						ApplicantNumber: this.ApplicantNumber,
						registerpic: this.imgsData.hukouben,
						propertypic: this.imgsData.fangben,
						avatar: this.imgsData.yqr
					};
				} else if (this.current === 0) {
					console.log('gongsi');
					data = {
						wxid: this.TOKEN,
						id: this.id,
						atype: '1',
						name: this.companyName,
						code: this.JDCode || this.XIANCode,
						pcode: this.PCSCode,
						address: this.address,
						comlegal: this.LegalPersonName, //法人姓名
						sex: this.legalSex, //法人性别
						useridno: this.identityNumber, //法人身份证号
						phone: this.phoneNumber, //法人手机号
						applyer: this.ApplicantName, //申请人姓名
						applyerphone: this.ApplicantNumber, //申请人手机号
						compic: this.imgsData.hukouben,
						propertypic: this.imgsData.fangben
					};
				}
				console.log(data);
				uni.request({
					url: this.URL + 'transfer',
					data: data,
					success: res => {
						uni.hideLoading();
						console.log(res.data);

						if (res.data.code === '200') {
							setTimeout(() => {
								uni.navigateBack();
							}, 1500);
						}
						CHONG.tip(res.data.msg); //单位
					},
					fail: res => {
						console.log(res.data);
					}
				});
			},
			switch1Change: function(e) {
				this.isTongyi = e.target.value;
				console.log('switch1 发生 change 事件，携带值为', e.target.value)
			},
			postTUpian(key) {
				uni.uploadFile({
					url: this.URL + 'uploadManage',
					filePath: this.imageList[key],
					name: key,
					success: res => {
						let json = JSON.parse(res.data);
						if (json.data[0].status) {
							this.imgsData[key] = this.imgIndex;
							this.imgsData[key] = json.data[0].fileName;

							this.imgIndex++;
							console.log(this.current);
							console.log(this.imgIndex);
							if (this.current === 1) {
								if (this.imgIndex === 3) {
									this.postGenren();
								}
							} else if (this.current === 0) {
								if (this.imgIndex === 2) {
									this.postGenren();
								}
							}

							return;
						}
						CHONG.tip('照片上传失败,请稍后再试');
					}
				});
			}, //表信息 提交
			submit() {
				console.log(`发送`);
				CHONG.tip('信息提交中', 0);
				this.validation();
			},
			//效验
			validation() {
				let idcardReg =
					/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
				if (this.current === 0) {
					if (!this.companyName) {
						CHONG.tip('请填写单位名称', 1);
						return;
					} else if (!this.XIANCode) {
						CHONG.tip('请选择单位地址', 1);
						return;
					} else if (!this.PCSCode) {
						CHONG.tip('请选择派出所', 1);
						return;
					} else if (!this.address) {
						CHONG.tip('请填写详细地址', 1);
						return;
					} else if (!this.LegalPersonName) {
						CHONG.tip('请填写法人姓名', 1);
						return;
					} else if (!this.identityNumber) {
						CHONG.tip('请填写法人身份证号', 1);
						return;
					} else if (!idcardReg.test(this.identityNumber)) {
						CHONG.tip('请填写正确格式的法人身份证号', 1);
						return;
					} else if (!this.phoneNumber) {
						CHONG.tip('请填写法人手机号', 1);
						return;
					} else if (this.phoneNumber.length !== 11 && this.phoneNumber.length !== 13) {
						CHONG.tip('请填写正确格式的法人手机号', 1);
						return;
					} else if (!this.ApplicantName) {
						CHONG.tip('请填写申请人姓名', 1);
						return;
					} else if (!this.ApplicantNumber) {
						CHONG.tip('请填写申请人手机号', 1);
						return;
					} else if (this.ApplicantNumber.length !== 11 && this.phoneNumber.length !== 13) {
						CHONG.tip('请填写正确格式的申请人手机号', 1);
						return;
					} else if (!this.ma) {
						CHONG.tip('请输入验证码');
						return;
					} else if (this.ma.length !== 4) {
						CHONG.tip('验证码不正确');
						return;
					} else if (!this.imageList.hukouben) {
						CHONG.tip('请上传营业执照', 1);
						return;
					} else if (!this.imageList.fangben) {
						CHONG.tip('请上传房本', 1);
						return;
					}

					let phone = '';
					if (this.current === 0) {
						phone = this.ApplicantNumber;
					} else {
						phone = this.phoneNumber;
					}
					if (this.ma.length === 4) {
						uni.request({
							url: this.URL + 'Msgchecked',
							data: {
								bizId: this.bizId,
								telephone: phone,
								checkNo: this.ma
							},
							success: res => {
								console.log('提交验证码了');
								console.log(res.data);
								if (res.data.success) {
									this.postTUpian('hukouben');
									this.postTUpian('fangben');
								} else {
									CHONG.tip('验证码不正确');
								}
							}
						});
					}
				} else if (this.current === 1) {
					if (!this.LegalPersonName) {
						CHONG.tip('请填写养犬人姓名', 1);
						return;
					} else if (!this.identityNumber) {
						CHONG.tip('请填写身份证号', 1);
						return;
					} else if (!idcardReg.test(this.identityNumber)) {
						CHONG.tip('请填写正确的身份证号', 1);
						return;
					} else if (!this.phoneNumber) {
						CHONG.tip('请填写手机号', 1);
						return;
					} else if (this.phoneNumber.length !== 11 && this.phoneNumber.length !== 13) {
						CHONG.tip('请填写正确的手机号', 1);
						return;
					} else if (!this.ma) {
						CHONG.tip('请输入验证码');
						return;
					} else if (this.ma.length !== 4) {
						CHONG.tip('验证码不正确');
						return;
					} else if (!this.XIANCode) {
						CHONG.tip('请选择暂居地', 1);
						return;
					} else if (!this.PCSCode) {
						CHONG.tip('请选择派出所', 1);
						return;
					} else if (!this.address) {
						CHONG.tip('请填写详细地址', 1);
						return;
					} else if (!this.contactName) {
						CHONG.tip('请填写紧急联系人姓名', 1);
						return;
					} else if (!this.ApplicantNumber) {
						CHONG.tip('请填写紧急联系人手机号', 1);
						return;
					} else if (this.ApplicantNumber.length !== 11 && this.phoneNumber.length !== 13) {
						CHONG.tip('请填写正确格式的紧急联系人手机号', 1);
						return;
					} else if (!this.imageList.hukouben) {
						CHONG.tip('请上传户口本', 1);
						return;
					} else if (!this.imageList.fangben) {
						CHONG.tip('请上传房本', 1);
						return;
					} else if (!this.imageList.yqr) {
						CHONG.tip('请上传养犬人照片', 1);
						return;
					}

					let phone = '';
					if (this.current === 0) {
						phone = this.ApplicantNumber;
					} else {
						phone = this.phoneNumber;
					}
					if (this.ma.length === 4) {
						uni.request({
							url: this.URL + 'Msgchecked',
							data: {
								bizId: this.bizId,
								telephone: phone,
								checkNo: this.ma
							},
							success: res => {
								console.log('提交验证码了');
								console.log(res.data);
								if (res.data.success) {
									this.postTUpian('hukouben');
									this.postTUpian('fangben');
									this.postTUpian('yqr');
								} else {
									CHONG.tip('验证码不正确');
								}
							}
						});
					}
				}
			},
			radioChangeLegalSex(e) {
				this.legalSex = e.detail.value;
			},
			radioChangeDogSex(e) {
				this.dogSex = e.detail.value;
			},
			chooseImg(q) {
				//选择图片
				uni.chooseImage({
					sourceType: ['camera', 'album'],
					count: 1,
					success: res => {
						this.imageList[q] = res.tempFilePaths[0];
						console.log(this.imageList[q]);
					}
				});
			},
			close(e) {
				this.imageList[e] = '';
			}
		},
		components: {
			uniSegmentedControl
		}
	};
</script>

<style lang="scss">
	.content {
		.con {
			font-size: 26upx;
			// .unit {
			padding: 20upx;

			.title {
				text-align: center;
				font-size: 28upx;
				font-weight: 700;
				margin-bottom: 20upx;
				padding-top: 50upx;
			}

			input {
				color: $chong-text-color;
				font-size: 24upx;
				margin: 10upx 0;
				padding: 4upx 20upx;

				border: {
					radius: 10upx;
					style: solid;
					width: 1upx;
					color: rgba($chong-text-color, 0.2);
				}

				background: white;
			}

			radio-group {
				padding: 20upx 0;

				label {
					.uni-radio-input-checked {
						background-color: $chong-iconbg-color !important;
					}

					padding: 0 10upx;
				}
			}

			/* 上传 */
			.uni-uploader {
				flex: 1;
				flex-direction: column;
				width: 100%;
			}

			.uni-uploader-info {
				color: #b2b2b2;
			}

			.uni-uploader-body {
				margin-top: 16upx;
			}

			.uni-uploader__files {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
			}

			.uni-uploader__file {
				width: 208upx;
				height: 208upx;
				margin: 10px auto;
			}

			.uni-uploader__img {
				display: block;
				width: 208upx;
				height: 208upx;
			}

			.uni-uploader__input-box {
				position: relative;
				margin: 10upx auto;
				width: 208upx;
				height: 208upx;
				border: 2upx solid #d9d9d9;
			}

			.uni-uploader__input-box:before,
			.uni-uploader__input-box:after {
				content: ' ';
				position: absolute;
				top: 50%;
				left: 50%;
				-webkit-transform: translate(-50%, -50%);
				transform: translate(-50%, -50%);
				background-color: #d9d9d9;
			}

			.uni-uploader__input-box:before {
				width: 4upx;
				height: 79upx;
			}

			.uni-uploader__input-box:after {
				width: 79upx;
				height: 4upx;
			}

			.uni-uploader__input-box:active {
				border-color: #999999;
			}

			.uni-uploader__input-box:active:before,
			.uni-uploader__input-box:active:after {
				background-color: #999999;
			}

			.uni-uploader__input {
				position: absolute;
				z-index: 1;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				opacity: 0;
			}

			.uni-uploader__file,
			.uni-uploader__input-box {
				width: 50%;
			}

			.close-view {
				text-align: center;
				line-height: 14px;
				height: 16px;
				width: 16px;
				border-radius: 50%;
				background: #ff5053;
				color: #ffffff;
				position: absolute;
				top: -6px;
				right: -4px;
				font-size: 12px;
			}

			.picBox>view {
				width: 50%;
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			// }
			// 		.personal {
			// 		}
		}

		.wenzi {
			margin: 40upx 0;
			line-height: 40upx;
			font-size: 16upx;
			text-align: center;
			color: #888888;
		}

		.btn {
			padding: 50upx 0;
			margin: 0 140upx;
		}
	}

	.huang {
		color: $chong-iconbg-color;
	}

	.uni-input {
		color: $chong-text-color;
		font-size: 24upx;
		margin: 10upx 0;
		padding: 17upx 20upx;

		border: {
			radius: 10upx;
			style: solid;
			width: 1upx;
			color: rgba($chong-text-color, 0.2);
		}

		background: white;
	}
	.mark {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		position: fixed;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
		background: rgba(0, 0, 0, .8);
		z-index: 9;
	
		.guanbi_btn {
			margin-bottom: 50upx;
			background: #000000;
			color: #F8F8F8;
			padding: 10upx 20upx;
			border-radius: 30%;
		}
	
		image {
			width: 750upx;
			height: 950upx;
			background: none;
		}
	}
</style>
